package com.gitee.wsl.mathematics.matrix.mat


/** 特化的对称矩阵 */
class SymmetricMatrix(data: List<Double>):FunMatrix(
    0,
    0,
    valueFun = {r,c->
        when {
            r >= c -> data[r * (r + 1) / 2 + c]
            else   -> data[c * (c + 1) / 2 + r]
        }
    }) {
    private val _dim:Int
    init {
        require(data.isNotEmpty())
        val temp = 8 * data.size + 1
        val delta = kotlin.math.sqrt(temp.toDouble()).toInt()
        require(temp == delta * delta)
        require(delta % 2 == 1)
        _dim = (delta - 1) / 2
    }

    override val rowCount: Int get() = _dim

    override val colCount: Int get() = _dim
}